<?php
    namespace Admin\Controller;

    use Org\Util\ArrayList;
    use Org\Util\Date;
    use Think\Controller;

    class ApiController extends Controller
    {
        public function index()
        {

        }
        public function menuInfo(){
            $dishs= M('dish')->select();
            $a = array();
            foreach ($dishs as $dishInfo){
                $dish = new \stdClass();
                $dish->itemId = $dishInfo['dish_id'];
                $dish->name = $dishInfo['dish_name'];
                $dish->image = __ROOT__.'/'.$dishInfo['dish_icon'];
                $dish->desc = $dishInfo['dish_description'];
                $dish->price = $dishInfo['dish_price'];
                array_push($a,$dish);
            }

            return show(21000, "成功",$a);

        }
        public function showPicture(){
            $id = I('id');
/*            print_r( __ROOT__.'/'.M('dish')->find($id)['dish_icon']);*/
            $data1['alt'] = '';
            $data1['pid'] = '';
            $path = M('dish')->find($id)['dish_icon'];
            $path =iconv("GB2312","UTF-8//IGNORE",$path);
           $data1['src'] = __ROOT__.'/'.$path;
            $data1['thumb'] = '';


            $rs = new \stdClass();
            $rs->title = "";
            $rs->id = "";
            $rs->start = 0;
            $data = array();
            $image1 = new \stdClass();
            $image1->alt = "";
            $image1->pid = $id;
            $image1->src = __ROOT__.'/'.$path;
            $image1->thumb = "";
            array_push($data, $image1);
            $rs->data = $data;
            exit(json_encode($rs));
        }

        public function addOrder(){
            $table = M('table');
            dump($table->find(1)['table_status'])  ;


        }
        public function showTable(){
            $table = M('table');
            $result = array();

            if($table->select()|| $table->select()==null){
                $result['code']=30011;
                $result['message']="请求桌号成功";
                $result['tableCount'] = count($table->select());
                $result['data']=$table->select();
/*                return show(30011, "请求桌号成功",$table->select());*/
            }else{
/*                return show(31011, "请求桌号失败");*/
                $result['code']=31011;
                $result['message']="请求桌号失败";
            }
            exit(json_encode($result));
        }

        public function getstr(){
            $str = trim(" 2017-09-22 00:00:00 ");
            print_r(substr($str,0,  strpos($str, " ")));
            echo substr($str, strpos($str, " "), strlen($str));
        }


    }